home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Find/Get distribution list *)
- (* *)
- (* Copyright 1990, 1991, 1992 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- (*===========================================================================*)
- (* Find a msg given the number *)
- (*===========================================================================*)
-
- FUNCTION find_msg(msg_no : WORD) : msg_index_ptr;
-
- VAR
- msg_index_current : msg_index_ptr;
-
- BEGIN;
-
- msg_index_current := msg_index_start;
-
- WHILE (msg_index_current <> NIL)
- AND (msg_index_current^.msg_i_mb.msg_number < msg_no) DO
- msg_index_current := msg_index_current^.msg_i_next;
-
- IF (msg_index_current = NIL)
- OR (msg_index_current^.msg_i_mb.msg_number <> msg_no)
- OR (NOT check_hidden(msg_index_current)) THEN
- find_msg := NIL
- ELSE
- find_msg := msg_index_current;
-
- END;
-
- (*===========================================================================*)
- (* If a distribution list is not in memory, go get it *)
- (*===========================================================================*)
-
- FUNCTION find_dist_list (i_ptr : msg_index_ptr) : msg_d_ptr;
-
- TYPE
- buffer_type = RECORD
- CASE BYTE OF
- 0: (buffer_msg : msg_block);
- 1: (buffer_dis : msg_dist_block_type);
- END;
-
- VAR
- buffer : buffer_type;
- rec_no : WORD;
- i : WORD;
- j : BYTE;
- new_blk : msg_d_ptr;
- new_ptr : ^msg_d_ptr;
-
- {$UNDEF DEBUG_GET_DIST_1}
-
- BEGIN;
-
- {$IFDEF DEBUG_GET_DIST_1}
- WRITELN('Dist get = ', i_ptr^.msg_i_mb.msg_number,
- ' ', i_ptr^.msg_i_dis = NIL);
- trace_data('GETDL', i_ptr^.msg_i_mb.msg_number, i_ptr^.msg_i_dis, '');
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* If the distribution list does not exist then we are done *)
- (*-----------------------------------------------------------------------*)
-
- IF (i_ptr^.msg_i_mb.msg_flag AND mf_fwd_list) = 0 THEN
- BEGIN;
- {$IFDEF POINT_CHK}
- test_pointer(NIL);
- {$ENDIF}
- {$IFNDEF POINT_CHK}
- EXIT;
- {$ENDIF}
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Get pointer to first block. We also need a pointer to where the *)
- (* pointer was obtained *)
- (*-----------------------------------------------------------------------*)
-
- new_blk := i_ptr^.msg_i_dis;
- new_ptr := ADDR(i_ptr^.msg_i_dis);
-
- {$IFDEF POINT_CHK}
- test_pointer(i_ptr);
- IF new_blk <> NIL THEN
- test_pointer(new_blk);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* See if we have a route block here. If we are supposed to have one *)
- (* and don't, then just turn it off. Otherwise use route_block *)
- (*-----------------------------------------------------------------------*)
-
- IF ((i_ptr^.msg_i_mb.msg_flag AND mf_disrout) <> 0) THEN
- IF new_blk = NIL THEN
- BEGIN;
- {$IFDEF POINT_CHK}
- test_pointer(NIL);
- {$ENDIF}
- i_ptr^.msg_i_mb.msg_flag := i_ptr^.msg_i_mb.msg_flag
- AND (NOT mf_disrout);
- END
- ELSE
- BEGIN;
- new_ptr := ADDR(i_ptr^.msg_i_dr^.msg_dr_dblk);
- new_blk := new_ptr^;
- {$IFDEF POINT_CHK}
- test_pointer(new_blk);
- {$ENDIF}
- END;
-
- (*-----------------------------------------------------------------------*)
- (* If the distribution list is already in memory, we are done *)
- (*-----------------------------------------------------------------------*)
-
- IF new_blk <> NIL THEN
- BEGIN;
- {$IFDEF POINT_CHK}
- test_pointer(new_blk);
- {$ENDIF}
- find_dist_list := new_blk;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Get number of record that we want *)
- (*-----------------------------------------------------------------------*)
-
- rec_no := i_ptr^.msg_i_record + 1;
-
- (*-----------------------------------------------------------------------*)
- (* Grab the lock so we can open the message file *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Open the msg file *)
- (*-----------------------------------------------------------------------*)
-
- RESET(msg_file);
-
- (*-----------------------------------------------------------------------*)
- (* Get the file size *)
- (*-----------------------------------------------------------------------*)
-
- i := FILESIZE(msg_file);
-
- (*-----------------------------------------------------------------------*)
- (* Verify gotten size versus calculated size and the position wanted *)
- (*-----------------------------------------------------------------------*)
-
- IF (i > next_record_no) OR (rec_no > next_record_no) THEN
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* The file sizes do not agree... PANIC *)
- (*-------------------------------------------------------------------*)
-
- dump_reason('Next record number computed and actual do not agree');
- dump_reason('or seek malfunction in GET_DIST');
- dump_reason('Computed =' + w2c(next_record_no) + ' Actual ='
- + w2c(i) + ' Seek =' + w2c (rec_no));
- dump_all;
- RUNERROR(msg_runerr);
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Set Position *)
- (*-----------------------------------------------------------------------*)
-
- SEEK(msg_file, rec_no);
-
- (*-----------------------------------------------------------------------*)
- (* Read in distribution list into buffer *)
- (*-----------------------------------------------------------------------*)
-
- READ(msg_file, buffer.buffer_msg);
-
- (*-----------------------------------------------------------------------*)
- (* Done with the file! *)
- (*-----------------------------------------------------------------------*)
-
- {$I-}
- CLOSE(msg_file);
- {$I+}
- i := IORESULT;
-
- (*-----------------------------------------------------------------------*)
- (* Release the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Get number of items in the array *)
- (*-----------------------------------------------------------------------*)
-
- i := buffer.buffer_dis.msg_d_no;
-
- (*-----------------------------------------------------------------------*)
- (* Validate *)
- (*-----------------------------------------------------------------------*)
-
- IF i > msg_dist_max THEN
- BEGIN;
- dump_reason('MF11 Invalid distribution # -- ' + w2c(i)
- + ' -- #' + w2c(i_ptr^.msg_i_mb.msg_number));
- dump_trace;
- dump_msg(i_ptr);
- RUNERROR(msg_runerr);
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Clear the flags in the distribution list *)
- (*-----------------------------------------------------------------------*)
-
- FOR j := 1 TO i DO
- WITH buffer.buffer_dis.msg_d_array[j] DO
- msg_d_flag := msg_d_flag AND NOT (df_fwd_select OR df_fwd_process);
-
- (*-----------------------------------------------------------------------*)
- (* Get the memory size needed to make it fit *)
- (*-----------------------------------------------------------------------*)
-
- i := 1 + i * SIZEOF(msg_dist_entry_type);
-
- GETMEM(new_blk, i);
-
- (*-----------------------------------------------------------------------*)
- (* Copy the data into the area *)
- (*-----------------------------------------------------------------------*)
-
- MOVE(buffer, new_blk^, i);
-
- (*-----------------------------------------------------------------------*)
- (* Update the pointer *)
- (*-----------------------------------------------------------------------*)
-
- new_ptr^ := new_blk;
- find_dist_list := new_blk;
-
- END;